package com.example.courseservice.controller;

import org.apache.dubbo.config.annotation.DubboReference;
import org.example.api.DubboDemoSerivce;
import org.example.application.service.xsgl.IXsxxAppService;
import org.example.infrastructure.utils.Msg;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

/**
 * @ClassName: CourseController
 * @Description:
 * @Author: YourName
 * @Date: 2023/10/27
 */
@RestController
@RequestMapping("course")
public class CourseController {
    @Autowired
    private RestTemplate restTemplate;

    @DubboReference
    private IXsxxAppService xsxxAppService;

    @RequestMapping("getUser")
    @ResponseBody
    public String getUserId() {
        String success = Msg.success();
        //打印日志
        System.out.println(success);
        //url
        String url = "http://studentService/student/restTemplate--";
        //使用RestTemplate 进行服务间调度 发送的是http 请求 http协议
        String xh = restTemplate.getForObject(url, String.class);
        return "CourseController" + xh;
    }

    @RequestMapping("getDubbo")
    @ResponseBody
    public String getDubbo() {
        //使用 dubbo 进行服务注册 rpc 调度 rpc 协议。 大面积服务间的调度 更推荐这个。
        //做到了响应更快 远程调用和本地调用无区别
        String dubbo = xsxxAppService.getMsg("dubbo 调用");
        return  dubbo;
    }
}
